package com.sean.gulimall.product.web;

import com.sean.gulimall.product.entity.CategoryEntity;
import com.sean.gulimall.product.service.CategoryService;
import com.sean.gulimall.product.vo.Catalog2Vo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * TODO
 *
 * @author 59244
 * @date 2022/1/15 12:27
 */
@Controller
public class IndexController {

    @Autowired
    CategoryService categoryService;

    @GetMapping({"/", "/index"})
    public String index(Model model){

        //TODO 1查出所有的1级分类
        List<CategoryEntity> categoryEntities = categoryService.getLevel1Categorys();

        model.addAttribute("categorys",categoryEntities);
        return "index";
    }


    /**
     * 功能描述：找到所有的二级分类
     * //index/catalog.json
     */
    @ResponseBody
    @GetMapping("/index/catalog.json")
    public Map<String, List<Catalog2Vo>> getCatalogJson(){
        Map<String, List<Catalog2Vo>> catalogJson = categoryService.getCatalogJson();
        return catalogJson;
    }


    /**
     * 功能描述：简单请求  压测使用
     */
    @ResponseBody
    @GetMapping("/hello")
    public String test(){
        return "hello";
    }
}
